package com.shudes.eval;

import java.util.*;

import com.shudes.game.*;

public class HandInspector {
	protected CardCollection cards;
	protected Map<Suit, Integer> suitCount; 
	protected Map<Rank, Integer> rankCount; 
	
	public HandInspector(CardCollection c) {
		cards=c;
		populateMaps();
	}
		
	public boolean containsSuit(Suit s) { 
		return getSuitCount(s) > 0; 
	}
	
	public boolean containsRank(Rank r) { 
		return getRankCount(r) > 0; 
	}
	
	public Integer getSuitCount(Suit s) { 
		Integer count; 
		
		count = suitCount.get(s); 
		return (count==null) ? 0 : count; 
	}
	
	public Integer getRankCount(Rank r) {
		Integer count;
		
		count = rankCount.get(r); 
		return (count==null) ? 0 : count; 		
	}
		
	protected void populateMaps() {
		Integer count; 
		
		suitCount = new HashMap<Suit, Integer>();
		for(Card c : cards.getCards()) { 
			count = suitCount.get(c.getSuit()); 
			suitCount.put(c.getSuit(), (count==null) ? new Integer(1) : ++count); 
		}
		
		rankCount = new HashMap<Rank, Integer>(); 
		for(Card c : cards.getCards()) { 
			count = rankCount.get(c.getRank()); 
			rankCount.put(c.getRank(), (count==null) ? new Integer(1) : ++count); 
		}
	}
}
